{
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3-final"
  },
  "orig_nbformat": 2,
  "kernelspec": {
   "name": "python38364bitbaseconda1416bbe678094f26900b55f191e6121b",
   "display_name": "Python 3.8.3 64-bit ('base': conda)"
  },
  "metadata": {
   "interpreter": {
    "hash": "638270506adf95aa1ec25a9d836fa33bbb50d23ee69454842566ab8fe7360dd4"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2,
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from sklearn.decomposition import PCA\n",
    "from sklearn.preprocessing import StandardScaler\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "dataFile = pd.read_csv(\"gemm/dump_csv/loop_0_space.csv\", index_col=False)\n",
    "dataFile.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "param = dataFile.columns[:-3]\n",
    "designVec = dataFile.loc[:, param].values\n",
    "# designVec = StandardScaler().fit_transform(designVec)\n",
    "pd.DataFrame(data=designVec, columns=param).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "pca = PCA(n_components=2)\n",
    "pcaDesignVec = pca.fit_transform(designVec)\n",
    "pca.explained_variance_ratio_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "pcaDataFile = pd.concat([pd.DataFrame(data=pcaDesignVec, columns=['pc0', 'pc1']),\n",
    "                         dataFile[['type']]], axis=1)\n",
    "pcaDataFile.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fig = plt.figure(figsize=(12, 8))\n",
    "ax = fig.add_subplot(1, 1, 1)\n",
    "ax.set_xlabel('Clock Cycles', fontsize=15)\n",
    "ax.set_ylabel('DSP Utilization', fontsize=15)\n",
    "ax.set_xscale('log')\n",
    "ax.set_yscale('log')\n",
    "ax.set_title('Latency-Area Profiling', fontsize=20)\n",
    "\n",
    "targets = ['non-pareto', 'pareto']\n",
    "colors = ['c', 'b']\n",
    "sizes = [10, 40]\n",
    "for target, color, size in zip(targets, colors, sizes):\n",
    "    pointsToKeep = dataFile['type'] == target\n",
    "    ax.scatter(dataFile.loc[pointsToKeep, 'cycle'],\n",
    "               dataFile.loc[pointsToKeep, 'dsp'],\n",
    "               c=color, s=size)\n",
    "ax.legend(targets, fontsize=15)\n",
    "ax.grid()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fig = plt.figure(figsize=(12, 8))\n",
    "ax = fig.add_subplot(1, 1, 1)\n",
    "ax.set_xlabel('Principal Component 0', fontsize=15)\n",
    "ax.set_ylabel('Principal Component 1', fontsize=15)\n",
    "ax.set_title('Design Space PCA', fontsize=20)\n",
    "\n",
    "# ax.set_xlim([-40, 80])\n",
    "# ax.set_ylim([-60, 60])\n",
    "\n",
    "targets = ['non-pareto', 'pareto']\n",
    "colors = ['c', 'b']\n",
    "sizes = [10, 40]\n",
    "for target, color, size in zip(targets, colors, sizes):\n",
    "    pointsToKeep = pcaDataFile['type'] == target\n",
    "    ax.scatter(pcaDataFile.loc[pointsToKeep, 'pc0'],\n",
    "               pcaDataFile.loc[pointsToKeep, 'pc1'],\n",
    "               c=color, s=size)\n",
    "ax.legend(targets, fontsize=15)\n",
    "ax.grid()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ]
}